home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr25 / rcd.zip / RCD.CMD next >
OS/2 REXX Batch file  |  1993-03-10  |  8KB  |  200 lines

  1. /*===========================================================================* 
  2.  *  RCD.CMD                                                     version 1.2  * 
  3.  *                                                                           * 
  4.  *  This REXX script can be used like the NCD command that is part of Norton * 
  5.  *  Utilities.  This is my first try at creating a useful REXX script.       * 
  6.  *  This script is FREEWARE.  Please use it all you wish, and If you can     * 
  7.  *  improve it, please do so.  All I ask is that if you change this command  * 
  8.  *  and distribute an improved version, that I get a copy of the changes.    * 
  9.  *  You can contact me with suggestions or bug reports on the Internet at    * 
  10.  *  'easyrob@cs.utexas.edu'.  Thanks.                                        * 
  11.  *                                                                           * 
  12.  *---------------------------------------------------------------------------* 
  13.  *  Usage: rcd [-r| r] <dirname>                                             * 
  14.  *                                                                           * 
  15.  *  Flags: -r      Reads current directory structure and updates the         * 
  16.  *                 rcd database.  The database is kept in \rcd.db on         * 
  17.  *                 the current drive and is automatically created If         * 
  18.  *                 it does not exist.                                        * 
  19.  *                                                                           * 
  20.  *  Changes current directory to a directory named in the database that      * 
  21.  *  matches or has <dirname> as a substring.  If there is more than one      * 
  22.  *  possible destination then each choice is shown and the ENTER key         * 
  23.  *  chooses the destination.  The TAB and arrow keys move through the        * 
  24.  *  list and the ESC key quits without changing the directory.               * 
  25.  *---------------------------------------------------------------------------* 
  26.  *  Developed by:  Robert D. Reynolds                                        * 
  27.  *                                                                           * 
  28.  *  The beginning: 07/07/92       RDR                                        * 
  29.  *           v1.0: 07/10/92       RDR                                        * 
  30.  *           v1.1: 07/11/92       RDR - Fixed bug with spaces in directory   * 
  31.  *                                      names.                               * 
  32.  *           v1.2: 07/14/92       RDR - Uses more REXX internal functions    * 
  33.  *                                      fixes bug when target was not found  * 
  34.  *                                      and problem with $DIRCMD.            * 
  35.  *                                                                           * 
  36.  *===========================================================================*/
  37. "@ECHO OFF"
  38.  
  39. /*-- Get arguements ---------------------------------------------------------*/
  40.  
  41. Arg arguements
  42. Parse Var arguements target rest
  43.  
  44. /*-- Set up variables -------------------------------------------------------*/
  45.  
  46. version = "1.2"
  47. data_base = '\rcd.db'
  48. re_read_db = 0
  49. exist_db = Lines(data_base)
  50. junk = Stream(data_base,C,'CLOSE')
  51.  
  52. /*-- Check for re-read database flag and trim Target ------------------------*/
  53.  
  54. If target="-R" | target="/R" Then 
  55. Do
  56.     re_read_db = 1
  57.     If rest<>"\" & rest<>"/" Then
  58.         target = FileSpec('NAME',rest)
  59. End
  60. Else If target<>"\" & target<>"/" Then 
  61.          target = FileSpec('NAME',target)
  62.  
  63. /*-- Create database If necessary -------------------------------------------*/
  64.  
  65. If exist_db=0 | re_read_db=1 Then
  66. Do
  67.      If re_read_db=1 & exist_db=1 Then 
  68.      Do
  69.          Call RxFuncAdd 'SysFileDelete', 'RexxUtil', 'SysFileDelete'
  70.          rc = SysFileDelete(data_base)
  71.          If rc<>0 Then
  72.          Do
  73.              Say " Unable to delete database; Aborting!"
  74.              Exit
  75.          End
  76.      End
  77.      Say " Creating the database for this drive...."
  78.      Call RxFuncAdd 'SysFileTree', 'RexxUtil', 'SysFileTree'
  79.      Call SysFileTree '\*', 'db.', 'SD'
  80.      Do i = 1 to db.0
  81.          Call LineOut data_base, SubWord(db.i,5)
  82.          if RC=1 Then Leave
  83.      End
  84.      junk = Stream(data_base,C,'CLOSE')
  85.      If RC=0 Then
  86.          Say " Database created successfully!"
  87.      Else
  88.      Do
  89.          Say " Error occurred while creating the database!"
  90.          Exit
  91.      End
  92. End
  93.  
  94. /*-- If no parameters display usage message ---------------------------------*/
  95.  
  96. If target="" & re_read_db=0 Then
  97. Do
  98.     Say " RCD v" || version || " by Robert D. Reynolds"
  99.     Say ""
  100.     Say " Usage: rcd [-r|/r] DirName"
  101.     Say ""
  102.     Say " Flags: -r     Reads current directory structure and updates the"
  103.     Say "               rcd database.  The database is kept in \rcd.db on"
  104.     Say "               the current drive and is automatically created If"
  105.     Say "               it does not exist."
  106.     Say ""
  107.     Say " Changes current directory to a directory named in the database that"
  108.     Say " matches or has DirName as a substring.  If there is more than one"
  109.     Say " possible destination then each choice is shown and the <ENTER> key"
  110.     Say " chooses the destination.  The <TAB> and arrow keys move through the"
  111.     Say " list and the <ESC> key quits without changing the directory."
  112.  
  113.     Exit
  114. End
  115.  
  116. If target="" Then Exit 
  117. If target="\" | target="/" Then 
  118. Do
  119.     Call Directory "\"
  120.     Exit
  121. End
  122.  
  123. /*-- Scan database ----------------------------------------------------------*/
  124.  
  125. dir_list.0 = 0
  126. matches.0 = 0
  127. possible_dirs.0 = 0
  128. current = directory()
  129.  
  130. Call RxFuncAdd 'SysFileSearch', 'RexxUtil', 'SysFileSearch'
  131. Call SysFileSearch target, data_base, 'dir_list.'
  132.  
  133. Do i = 1 to dir_list.0
  134.     d = Translate( dir_list.i )
  135.     subd = FileSpec("NAME",d)
  136.     If d=current Then                 /* Do not include If current directory */
  137.         Iterate
  138.     If target=subd Then               /* If exact match add to matches */
  139.     Do
  140.         j = matches.0 + 1
  141.         matches.j = d
  142.         matches.0 = j
  143.     End
  144.     If Pos(target,subd)>=1 Then       /* If substring add to possible_dirs */
  145.     Do
  146.         j = possible_dirs.0 + 1
  147.         possible_dirs.j = d
  148.         possible_dirs.0 = j
  149.     End
  150. End
  151.  
  152. /*-- Change directory -------------------------------------------------------*/
  153.  
  154. Select
  155.     When matches.0=1                              /* Just one match */
  156.         Then Call Directory matches.1
  157.     When possible_dirs.0=1                        /* Just one possible */
  158.         Then Call Directory possible_dirs.1
  159.     When possible_dirs.0>1                        /* Ask user what directory */
  160.         Then
  161.         Do
  162.             Call RxFuncAdd 'SysCurPos', 'RexxUtil', 'SysCurPos'
  163.             Call RxFuncAdd 'SysGetKey', 'RexxUtil', 'SysGetKey'
  164.  
  165.             found=0
  166.             i = 1 
  167.             Do Forever
  168.                 Say Left(Strip(Right(possible_dirs.i,79)),79)
  169.                 Parse Value SysCurPos() With row col
  170.                 inkey = 0
  171.                 Do While inkey=224 | inkey=0      /* Throw away modIfier key */
  172.                     Parse Value SysGetKey('NOECHO') With key
  173.                     inkey = c2d(key)
  174.                 End
  175.                 select
  176.                     When inkey=27                          /*ESC*/
  177.                         Then Exit 
  178.                     When inkey=72 | inkey=75 | inkey=15    /* UP,RT,SHFT-TAB */
  179.                         Then If I<>1 Then I = I - 1
  180.                     When inkey=13                          /* CR */
  181.                         Then
  182.                         Do 
  183.                             found=1
  184.                             Leave
  185.                         End
  186.                 Otherwise
  187.                     If I<>possible_dirs.0 Then I = I + 1
  188.                 End
  189.                 junk = SysCurPos(row-1,0)
  190.             End
  191.             If found Then Call Directory possible_dirs.i
  192.         End
  193. Otherwise
  194.     Say " No Match Found!"
  195. End
  196.  
  197. Exit
  198.  
  199. /*---------------------------------------------------------------------------*/
  200.